<?php

    //Sub Table Class define
    include_once("ClassSub.php");

class MLSInformationClass
{
	var $ListingStatus;	// attr Status="Active"/>
	var $OriginalListPrice;// CurrencyCode="USD" Type="FLOAT"/>
	var $ListingArea;
	var $StatusChangeDate;// Format="YYYY-MM-DD" Type="DATE"/>
    var $DaysOnMarket;// Type="INTEGER"/>
    var $ListingServiceName;
	
	var $ID;
		
	function AddItemFromXML($XmlArray)
	{
		$Array = $XmlArray->children();
			
	 	$this->ListingStatus = $Array[0]->attributes("Status");
	 	$this->OriginalListPrice = new CurrencyFormatClass;
		$this->OriginalListPrice->AddItemFromXML($Array[1]);
		$this->ListingArea = $Array[2];
	 	$this->StatusChangeDate = $Array[3];
		$this->DaysOnMarket = $Array[4];
		$this->ListingServiceName = $Array[5];
	}
	
	function InsertSQL()
	{
		$this->OriginalListPrice->InsertSQL();		

		$strSqlCommand = "INSERT INTO MLSInformation( ListingStatus, OriginalListPrice, ";
		$strSqlCommand .="ListingArea, StatusChangeDate, DaysOnMarket, ListingServiceName) ";
		$strSqlCommand .= "VALUES( '".$this->ListingStatus."', ";
		$strSqlCommand .= "'".$this->OriginalListPrice->ID."', ";
		$strSqlCommand .= "'".$this->ListingArea."', ";
		$strSqlCommand .= "'".$this->StatusChangeDate."', ";
		$strSqlCommand .= "'".$this->DaysOnMarket."', ";
		$strSqlCommand .= "'".$this->ListingServiceName."') ";
				
		if(!mysql_query($strSqlCommand))
		{
			echo $strSqlCommand."<br/>";
		}
		$this->ID = mysql_insert_id();		
	}
	
	function ModifySQL( $InputID )
	{
		$this->ID = $InputID;

		$strSqlCommand = "SELECT * FROM MLSInformation ";
		$strSqlCommand .= " WHERE idMLSInformation = '".$this->ID."' ";
		$result = mysql_query($strSqlCommand);
		$rowListingData = @mysql_fetch_array($result);

		$strSqlCommand =  "UPDATE MLSInformation SET ";
		$strSqlCommand .= "ListingStatus='"		.$this->ListingStatus		."', ";
		$strSqlCommand .= "ListingArea='"		.$this->ListingArea			."', ";
		$strSqlCommand .= "StatusChangeDate='"	.$this->StatusChangeDate	."', ";
		$strSqlCommand .= "DaysOnMarket='"		.$this->DaysOnMarket		."', ";
		$strSqlCommand .= "ListingServiceName='".$this->ListingServiceName	."' ";
		$strSqlCommand .= "WHERE idMLSInformation = ".$this->ID;
		mysql_query($strSqlCommand);

		$this->OriginalListPrice->ModifySQL( $rowListing["OriginalListPrice"]);			
	}	
}

?>